package com.fallsvc.re.networkprogramming.file.test;

import java.io.File;
import java.io.IOException;

/**
 * @auther falls_vc
 * description:
 * @date 2025/11/3  14:46
 */
public class Demo1 {

    public static void main1(String[] args) throws IOException {
        File file = new File("..\\hello-world.txt"); // 并不要求该⽂件真实存
        System.out.println(file.getParent());
        System.out.println(file.getName());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getCanonicalPath());
    }
    public static void main2(String[] args) throws IOException {
        File file = new File("hello-world.txt"); // 要求该⽂件不存在，才能看
//        System.out.println(file.exists());
//        System.out.println(file.isDirectory());
//        System.out.println(file.isFile());
//        System.out.println(file.createNewFile());
//        System.out.println(file.exists());
//        System.out.println(file.isDirectory());
//        System.out.println(file.isFile());
//        System.out.println(file.createNewFile());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.exists());
        System.out.println(file.delete());
        System.out.println(file.exists());
    }
    public static void main3(String[] args) throws IOException {
        File dir = new File("some-dir"); // 要求该⽬录不存在，才能看到相同的现
        System.out.println(dir.isDirectory());
        System.out.println(dir.isFile());
        System.out.println(dir.mkdir());
        System.out.println(dir.isDirectory());
        System.out.println(dir.isFile());
    }
    public static void main4(String[] args) throws IOException {
        File dir = new File("some-parent/some-dir"); // some-parent 和 so
        System.out.println(dir.isDirectory());
        System.out.println(dir.isFile());
        System.out.println(dir.mkdirs());
        System.out.println(dir.isDirectory());
        System.out.println(dir.isFile());

    }
    public static void main(String[] args) throws IOException {
        File file = new File("some-file.txt"); // 要求 some-file.txt 得存在
        File dest = new File("dest.txt"); // 要求 dest.txt 不存在
        file.createNewFile();
        System.out.println(file.exists());
        System.out.println(dest.exists());
        System.out.println(file.renameTo(dest));
        System.out.println(file.exists());
        System.out.println(dest.exists());
    }
}
